home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / vbkontrol.exe / IPD_102N.ZIP / FTP.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-24  |  12.6 KB  |  430 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "FTP Demo - Please refer to RFC959 for more info."
  5.    ClientHeight    =   5385
  6.    ClientLeft      =   1185
  7.    ClientTop       =   1500
  8.    ClientWidth     =   8640
  9.    Height          =   5790
  10.    Left            =   1125
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5385
  13.    ScaleWidth      =   8640
  14.    Top             =   1155
  15.    Width           =   8760
  16.    Begin Frame Frame2 
  17.       BackColor       =   &H00C0C0C0&
  18.       Caption         =   "Operation"
  19.       Height          =   1095
  20.       Left            =   3120
  21.       TabIndex        =   20
  22.       Top             =   1080
  23.       Width           =   1935
  24.       Begin OptionButton oWhat 
  25.          BackColor       =   &H00C0C0C0&
  26.          Caption         =   "List"
  27.          Height          =   255
  28.          Index           =   2
  29.          Left            =   240
  30.          TabIndex        =   23
  31.          Top             =   720
  32.          Width           =   1335
  33.       End
  34.       Begin OptionButton oWhat 
  35.          BackColor       =   &H00C0C0C0&
  36.          Caption         =   "<--Download"
  37.          Height          =   255
  38.          Index           =   1
  39.          Left            =   240
  40.          TabIndex        =   22
  41.          Top             =   480
  42.          Width           =   1455
  43.       End
  44.       Begin OptionButton oWhat 
  45.          BackColor       =   &H00C0C0C0&
  46.          Caption         =   "Upload-->"
  47.          Height          =   255
  48.          Index           =   0
  49.          Left            =   240
  50.          TabIndex        =   21
  51.          Top             =   240
  52.          Value           =   -1  'True
  53.          Width           =   1335
  54.       End
  55.    End
  56.    Begin CommandButton Command2 
  57.       Caption         =   "GO!!"
  58.       Height          =   375
  59.       Left            =   5400
  60.       TabIndex        =   19
  61.       Top             =   1800
  62.       Width           =   1215
  63.    End
  64.    Begin CommandButton Command1 
  65.       Caption         =   "Cancel"
  66.       Height          =   375
  67.       Left            =   6840
  68.       TabIndex        =   18
  69.       Top             =   1800
  70.       Width           =   1095
  71.    End
  72.    Begin Frame Frame1 
  73.       BackColor       =   &H00C0C0C0&
  74.       Caption         =   "PI State"
  75.       Height          =   1335
  76.       Left            =   6960
  77.       TabIndex        =   14
  78.       Top             =   0
  79.       Width           =   1575
  80.       Begin OptionButton oState 
  81.          BackColor       =   &H00C0C0C0&
  82.          Caption         =   "COMMAND"
  83.          Enabled         =   0   'False
  84.          ForeColor       =   &H0000FFFF&
  85.          Height          =   255
  86.          Index           =   2
  87.          Left            =   120
  88.          TabIndex        =   17
  89.          Top             =   960
  90.          Width           =   1335
  91.       End
  92.       Begin OptionButton oState 
  93.          BackColor       =   &H00C0C0C0&
  94.          Caption         =   "WAITING"
  95.          Enabled         =   0   'False
  96.          ForeColor       =   &H000000FF&
  97.          Height          =   255
  98.          Index           =   1
  99.          Left            =   120
  100.          TabIndex        =   16
  101.          Top             =   600
  102.          Width           =   1215
  103.       End
  104.       Begin OptionButton oState 
  105.          BackColor       =   &H00C0C0C0&
  106.          Caption         =   "IDLE"
  107.          Enabled         =   0   'False
  108.          ForeColor       =   &H0000FF00&
  109.          Height          =   255
  110.          Index           =   0
  111.          Left            =   120
  112.          TabIndex        =   15
  113.          Top             =   240
  114.          Value           =   -1  'True
  115.          Width           =   855
  116.       End
  117.    End
  118.    Begin IPPORT IPPort1 
  119.       EOL             =   ""
  120.       InBufferSize    =   2048
  121.       Left            =   1680
  122.       Linger          =   -1  'True
  123.       LocalPort       =   0
  124.       OutBufferSize   =   2048
  125.       Port            =   0
  126.       Top             =   960
  127.    End
  128.    Begin IPDAEMON IPDaemon1 
  129.       EOL             =   ""
  130.       InBufferSize    =   2048
  131.       Left            =   2160
  132.       Linger          =   -1  'True
  133.       OutBufferSize   =   2048
  134.       Port            =   0
  135.       Top             =   960
  136.    End
  137.    Begin OptionButton optBinary 
  138.       BackColor       =   &H00C0C0C0&
  139.       Caption         =   "BINARY"
  140.       Height          =   255
  141.       Index           =   1
  142.       Left            =   1560
  143.       TabIndex        =   13
  144.       Top             =   1800
  145.       Width           =   975
  146.    End
  147.    Begin OptionButton optASCII 
  148.       BackColor       =   &H00C0C0C0&
  149.       Caption         =   "ASCII"
  150.       Height          =   255
  151.       Index           =   0
  152.       Left            =   360
  153.       TabIndex        =   12
  154.       Top             =   1800
  155.       Value           =   -1  'True
  156.       Width           =   975
  157.    End
  158.    Begin CommandButton bConnect 
  159.       Caption         =   "Connect!!"
  160.       Height          =   375
  161.       Left            =   5280
  162.       TabIndex        =   11
  163.       Top             =   180
  164.       Width           =   1335
  165.    End
  166.    Begin TextBox tOutput 
  167.       FontBold        =   0   'False
  168.       FontItalic      =   0   'False
  169.       FontName        =   "Courier New"
  170.       FontSize        =   8.25
  171.       FontStrikethru  =   0   'False
  172.       FontUnderline   =   0   'False
  173.       Height          =   3135
  174.       HideSelection   =   0   'False
  175.       Left            =   0
  176.       MousePointer    =   1  'Arrow
  177.       MultiLine       =   -1  'True
  178.       ScrollBars      =   3  'Both
  179.       TabIndex        =   10
  180.       Top             =   2280
  181.       Width           =   8655
  182.    End
  183.    Begin TextBox tRemote 
  184.       Height          =   285
  185.       Left            =   5280
  186.       TabIndex        =   7
  187.       Text            =   "/pub/README"
  188.       Top             =   1440
  189.       Width           =   2775
  190.    End
  191.    Begin TextBox tLocal 
  192.       Height          =   285
  193.       Left            =   120
  194.       TabIndex        =   6
  195.       Text            =   "C:\FTPTEST.TXT"
  196.       Top             =   1440
  197.       Width           =   2775
  198.    End
  199.    Begin TextBox tPassword 
  200.       Height          =   285
  201.       Left            =   4440
  202.       TabIndex        =   5
  203.       Text            =   "elf@north.pole.com"
  204.       Top             =   720
  205.       Width           =   2295
  206.    End
  207.    Begin TextBox tUserID 
  208.       Height          =   285
  209.       Left            =   1320
  210.       TabIndex        =   4
  211.       Text            =   "anonymous"
  212.       Top             =   720
  213.       Width           =   1575
  214.    End
  215.    Begin TextBox tHost 
  216.       Height          =   285
  217.       Left            =   1320
  218.       TabIndex        =   0
  219.       Text            =   "little"
  220.       Top             =   240
  221.       Width           =   3615
  222.    End
  223.    Begin Label Label1 
  224.       BackStyle       =   0  'Transparent
  225.       Caption         =   "Remote File"
  226.       Height          =   255
  227.       Index           =   4
  228.       Left            =   5280
  229.       TabIndex        =   9
  230.       Top             =   1200
  231.       Width           =   1575
  232.    End
  233.    Begin Label Label1 
  234.       BackStyle       =   0  'Transparent
  235.       Caption         =   "Local File"
  236.       Height          =   255
  237.       Index           =   3
  238.       Left            =   120
  239.       TabIndex        =   8
  240.       Top             =   1200
  241.       Width           =   1575
  242.    End
  243.    Begin Label Label1 
  244.       BackStyle       =   0  'Transparent
  245.       Caption         =   "Password:"
  246.       Height          =   255
  247.       Index           =   2
  248.       Left            =   3360
  249.       TabIndex        =   3
  250.       Top             =   720
  251.       Width           =   975
  252.    End
  253.    Begin Label Label1 
  254.       BackStyle       =   0  'Transparent
  255.       Caption         =   "User ID:"
  256.       Height          =   255
  257.       Index           =   1
  258.       Left            =   120
  259.       TabIndex        =   2
  260.       Top             =   720
  261.       Width           =   855
  262.    End
  263.    Begin Label Label1 
  264.       BackStyle       =   0  'Transparent
  265.       Caption         =   "Host Name:"
  266.       Height          =   255
  267.       Index           =   0
  268.       Left            =   120
  269.       TabIndex        =   1
  270.       Top             =   240
  271.       Width           =   1095
  272.    End
  273. Option Explicit
  274. Dim rLocalAddress As String
  275. Dim rResponseCode As Integer
  276. Dim rResponseText As String
  277. Const S_IDLE = 0
  278. Const S_WAITING = 1
  279. Const S_COMMAND = 2
  280. Const M_UPLOAD = 0
  281. Const M_DOWNLOAD = 1
  282. Const M_LIST = 2
  283. Sub bConnect_Click ()
  284. tOutput = ""
  285. Screen.MousePointer = 11
  286. IPPort1.Connected = False 'disconnect previous connection
  287. IPPort1.EOL = Chr$(13) & Chr$(10)
  288. IPPort1.HostName = tHost
  289. IPPort1.Port = 21
  290. IPPort1.Connected = True
  291. 'wait for connection - give it 10 seconds
  292. Dim After10Seconds: After10Seconds = Now + 10# / (3600# * 24#)
  293. Do Until Now > After10Seconds
  294.     If IPPort1.Connected Then Exit Do
  295.     DoEvents
  296. If Not IPPort1.Connected Then
  297.     MsgBox "Connection timed out!!"
  298.     GoTo Done
  299. End If
  300. SendCommand ""  'get server welcome message
  301. 'login
  302. SendCommand "USER " & tUserID
  303. 'wait for server response
  304. Do: DoEvents: Loop Until rResponseCode <> 0
  305. 'now send password
  306. SendCommand "PASS " & tPassword
  307. Done:
  308. Screen.MousePointer = 0
  309. End Sub
  310. Sub Command1_Click ()
  311. SendCommand "ABOR"
  312. Screen.MousePointer = 0
  313. End Sub
  314. Sub Command2_Click ()
  315. PrepareDataPort
  316. Screen.MousePointer = 11
  317. If oWhat(M_UPLOAD) Then
  318.     oWhat(M_UPLOAD).ForeColor = &HFF&
  319.     Open tLocal For Binary As #1
  320.     SendCommand "STOR " & tRemote
  321. ElseIf oWhat(M_DOWNLOAD) Then
  322.     oWhat(M_DOWNLOAD).ForeColor = &HFF&
  323.     Open tLocal For Binary As #1
  324.     SendCommand "RETR " & tRemote
  325. Else 'oWhat(M_LIST) then
  326.     oWhat(M_LIST).ForeColor = &HFF&
  327.     SendCommand "LIST " & tRemote
  328. End If
  329. End Sub
  330. Sub Form_Load ()
  331. IPPort1.HostName = IPPort1.LocalHostName
  332. rLocalAddress = IPPort1.HostAddress
  333. End Sub
  334. Sub Form_Resize ()
  335. tOutput.Width = ScaleWidth
  336. tOutput.Height = Scaleheight - tOutput.Top
  337. End Sub
  338. Sub IPDaemon1_Connected (ConnectionID As Integer, StatusCode As Integer, Description As String)
  339. On Error GoTo FlowControl
  340. If oWhat(M_UPLOAD) Then
  341.     Dim Text$
  342.     Do While Not EOF(1)
  343.         Text$ = Input$(1400, #1)
  344.         IPDaemon1.DataToSend(ConnectionID) = Text$
  345.     Loop
  346.     IPDaemon1.Connected(ConnectionID) = False
  347. End If
  348. Exit Sub
  349. FlowControl:
  350. If Err = 25036 Then
  351.     Dim BytesSent%: BytesSent% = IPDaemon1.BytesSent
  352.     If BytesSent% > 0 Then  'strip bytes sent
  353.         Text$ = Mid$(Text$, BytesSent% + 1)
  354.     End If
  355.     DoEvents   'wait a while
  356.     Resume     'try again
  357. Else  'handle other errors here
  358.     MsgBox Error$
  359.     Exit Sub
  360. End If
  361. End Sub
  362. Sub IPDaemon1_DataIn (ConnectionID As Integer, Text As String, EOL As Integer)
  363. If oWhat(M_LIST) Then
  364.     Trace Text
  365. ElseIf oWhat(M_DOWNLOAD) Then
  366.     Put #1, , Text
  367. End If
  368. End Sub
  369. Sub IPDaemon1_Disconnected (ConnectionID As Integer, StatusCode As Integer, Description As String)
  370. Screen.MousePointer = 0
  371. IPDaemon1.Listening = False
  372. Close #1
  373. oWhat(M_UPLOAD).ForeColor = 0
  374. oWhat(M_DOWNLOAD).ForeColor = 0
  375. oWhat(M_LIST).ForeColor = 0
  376. End Sub
  377. Sub IPPort1_DataIn (Text As String, EOL As Integer)
  378. 'trace
  379. Trace Text
  380. rResponseText = rResponseText & Text
  381. 'full line?
  382. If EOL Then
  383.     Trace Chr$(13) & Chr(10)
  384.     If Mid$(Text, 4, 1) = " " Then
  385.         rResponseCode = CInt(Left$(rResponseText, 3))
  386.         rResponseText = Mid$(rResponseText, 5)
  387.         'elaborate error checking should go here
  388.         'please see RFC959 for more information
  389.         If rResponseCode \ 100 = 1 Then
  390.             oState(S_WAITING) = True
  391.         Else
  392.             oState(S_IDLE) = True
  393.         End If
  394.     End If
  395.     rResponseText = ""  'reset buffer
  396. End If
  397. End Sub
  398. Sub optASCII_Click (Index As Integer)
  399. SendCommand "TYPE A"
  400. End Sub
  401. Sub optBinary_Click (Index As Integer)
  402. SendCommand "TYPE I"
  403. End Sub
  404. Sub PrepareDataPort ()
  405. IPDaemon1.Listening = True
  406. Dim Port: Port = IPDaemon1.Port
  407. Dim i%, x%, address$
  408. address$ = rLocalAddress
  409. For i% = 1 To 3
  410.     x% = InStr(address$, ".")
  411.     If x% <> 0 Then Mid$(address$, x%, 1) = ","
  412. Next i%
  413. SendCommand "PORT " & address$ & "," & Port \ 256 & "," & Port Mod 256
  414. End Sub
  415. 'sends an FTP command to the server
  416. 'and returns the response code
  417. Sub SendCommand (CommandText$)
  418. rResponseCode = 0
  419. If CommandText$ <> "" Then
  420.     Trace CommandText$ & Chr$(13) & Chr$(10)
  421.     oState(S_COMMAND) = True
  422.     IPPort1.DataToSend = CommandText$ & Chr$(10)
  423. End If
  424. End Sub
  425. Sub Trace (Text As String)
  426. tOutput.SelStart = Len(tOutput)
  427. tOutput.SelLength = 0
  428. tOutput.SelText = Text
  429. End Sub
  430.